package com.millstein.tsinglog.mapper.biz;

import com.millstein.tsinglog.mapper.BaseMapper;
import com.millstein.tsinglog.model.pojo.Comment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * server用，根据id查询评论
     * @param id
     * @return
     */
    @Select("SELECT `id`, `author_name` authorName, `author_photo` authorPhoto, `author_ip` authorIp, `location`, " +
            "`email`, `aid`, `floor`, `comment_content` commentContent, `pre_comment_id` preCommentId, " +
            "`support_count` supportCount, `oppose_count` opposeCount, `comment_status` commentStatus, " +
            "`failure_info` failureInfo, `check_time` checkTime, `status`, `create_time` createTime, " +
            "`update_time` updateTime FROM `biz_comment` " +
            "where `status` = 1 and `id` = #{id};")
    Comment selectCommentByPrimaryKeyForServer(@Param("id") Long id);

    /**
     * web用，根据id查询评论
     * @param id
     * @return
     */
    @Select("SELECT `id`, `author_name` authorName, `author_photo` authorPhoto, `author_ip` authorIp, `location`, " +
            "`email`, `aid`, `floor`, `comment_content` commentContent, `pre_comment_id` preCommentId, " +
            "`support_count` supportCount, `oppose_count` opposeCount, `comment_status` commentStatus, " +
            "`failure_info` failureInfo, `check_time` checkTime, `status`, `create_time` createTime, " +
            "`update_time` updateTime FROM `biz_comment` " +
            "where `comment_status` = 2 and `status` = 1 and `id` = #{id};")
    Comment selectCommentByPrimaryKeyForWeb(@Param("id") Long id);
    /**
     * 根据文章id查询所有审核通过并且未删除的评论数量
     * @param aid
     * @return
     */
    @Select("SELECT ifNull(max(floor), 0) FROM `biz_comment` where aid = #{aid}")
    int getCommentByAid(@Param("aid") Long aid);

    /**
     * 根据floor的值获取评论的id值
     * @param floor
     * @return
     */
    @Select("select id from `biz_comment` where floor = #{floor}")
    Long getIdByFloor(@Param("floor") Integer floor);
}
